package com.cqeec.gams.service;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cqeec.gams.dao.RoleMapper;
import com.cqeec.gams.dao.RolePermissionsMapper;
import com.cqeec.gams.entity.Role;
import com.cqeec.gams.entity.RolePermissions;

@Service
public class RoleServiceImpl implements RoleService {
	@Autowired
	private RoleMapper roleMapper;
	@Autowired
	private RolePermissionsMapper rpMapper;

	@Override
	public long count() {
		return roleMapper.count();
	}

	@Override
	public List<Role> findAll() {
		return roleMapper.findAll();
	}

	@Override
	public Role findById(String id) {
		return roleMapper.findById(id);
	}

	@Override
	public void insert(Role entity) {
		if (entity.getId() == null || "".equals(entity.getId())) {
			entity.setId(UUID.randomUUID().toString());
		}
		roleMapper.insert(entity);
	}

	@Override
	public void update(Role entity) {
		roleMapper.update(entity);
	}

	@Override
	public void delete(String id) {
		roleMapper.delete(id);
	}

	@Override
	public List<Role> findPage(int page, int size) {
		long startRow = (page - 1) * size;
		return roleMapper.findPage(startRow, size);
	}

	@Override
	public void inserRolePermission(RolePermissions rp) {
		rpMapper.insert(rp);
	}

	@Override
	public void deleteRolePermissions(String roleId) {
		rpMapper.deleteRolePermissions(roleId);
	}

}
